import service from '@/request'

import { data, lineData } from './response'
export function testTreeData() {
  return new Promise((resovle) => {
    resovle({
      data: data
    })
  })
}

export function getLineList() {
  return new Promise((resovle) => {
    resovle(lineData)
  })
}

export function getDepaertTree(params: any) {
  return service.request({
    url: '/wisdom/prob/page',
    params
  })
}

export interface CommonUploadFile {
  url: string
  filename: string
  mimeType?: string
  [x: string]: any
}

interface UploadInter extends ResponseResultTypes {
  data: CommonUploadFile
}

export const uploadCommon = async (
  formData: FormData
): Promise<{
  data: CommonUploadFile
}> => {
  const res = await service.request<UploadInter>({
    url: 'xxx',
    data: formData,
    method: 'POST'
  })
  return {
    data: {
      url: res.data.url,
      filename: res.data.fileName,
      mimeType: res.data.fileType
    }
  }
}

export async function uploadImg(data: FormData) {
  const res = await service.request({
    url: 'xxx',
    data,
    method: 'POST'
  })
  return {
    data: {
      url: res.path,
      filename: res.fileName,
      mimeType: res.fileType
    }
  }
}

export function keyWordExcelExportTemplate(data: any) {
  return service.instance.request({
    url: '/political/keywordslibrary/exportExcel?orgUuid=' + data.orgUuid,
    method: 'POST',
    responseType: 'blob'
  })
}

export function exportExcelData(data: any) {
  return service.request({
    url: '/political/keywordslibrary/importData',
    data,
    method: 'POST'
  })
}

export interface DataType {
  id: number
  createdAt: string
  updatedAt: string
  indicatorSystemName: string
  yearly: string
  startDate: null
  endDate: null
  creator: string
  isUse: number
  isLock: number
  yearlyId: null
  deptName: null
  oneIndicatNum: number
  twoIndicatNum: number
  monitNum: number
  keyWordNum: number
  doIndId: null
  indicatorType: number
}

export interface ResponseTest {
  total: number
  size: number
  current: number
  orders: any[]
  optimizeCountSql: boolean
  searchCount: boolean
  maxLimit: null
  countId: null
  pages: number
  records: DataType[]
}

export function getTestList(params: any) {
  return service.request<ResponseTest>(
    {
      url: '/political/yearlyindicatormaintenance/page',
      params
    },
    {
      isNotToken: true
    }
  )
}

export function delTestData(data: any) {
  return service.request({
    url: '/political/yearlyindicatormaintenance/deleteBatch',
    data,
    method: 'DELETE'
  })
}

export function editTestData(id: number, data: any) {
  return service.request({
    url: '/political/yearlyindicatormaintenance/updateDetails',
    data: {
      ...data,
      id
    },
    method: 'PUT'
  })
}

interface DetailInter {
  id: number
  createdAt: string
  updatedAt: string
  indicatorSystemName: string
  yearly: string
  startDate: null
  endDate: null
  creator: string
  isUse: number
  isLock: number
  yearlyId: null
  deptName: null
  oneIndicatNum: null
  twoIndicatNum: null
  monitNum: null | number
  keyWordNum: null | string | number
  doIndId: null
  indicatorType: number
}

export function testGetDetail() {
  return service.request<DetailInter>({
    url: '/political/yearlyindicatormaintenance/info/52'
  })
}
